// DrawLine.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <Windows.h>

#define __USER_STATIC_LIBRARY
#include "..\\..\\include\\JHComm.h"


#pragma comment (lib, "..\\..\\lib\\Windows\\jinhancomm.lib")
#pragma comment (lib, "..\\..\\lib\\Windows\\jinhanzk.lib")

#define COMM_SERIALPORT  1


int _tmain(int argc, _TCHAR* argv[])
{
	HANDLE hdl;
	HANDLE pargstruct;
	HANDLE pjhtransportlayer;
	int ret;
	JHZRESULT res;

	/* Create instance */
	res = JHCreateInst(&hdl, 0);
	if (JR_OK != res)
	{
		printf("\nFailure to JHCreateInst!\n");
		ret = -1;
		goto ERROR_OPERATION;
	}

	res = JHCommInit();
	if(JR_OK != res)
	{
		printf("\nFailure to JHCommInit!\n");
		ret = -1;
		goto ERROR_OPERATION;
	}

#if COMM_SERIALPORT
	res = JHCommGetTransportlayer(&pjhtransportlayer, DEV_SERIALPORT);
	if(JR_OK != res)
	{
		printf("\nFailure to JHCommGetTransportlayer!\n");
		ret = -1;
		goto ERROR_OPERATION;
	}

	res = JHCommGetSerialportArgStruct(&pargstruct, "COM1", 115200, 8, 0, 0, 5000);
	if(JR_OK != res)
	{
		printf("\nFailure to JHCommGetSerialportArgStruct!\n");
		ret = -1;
		goto ERROR_OPERATION;
	}
#else
	res = JHCommGetTransportlayer(&pjhtransportlayer, DEV_TCP);
	if(JR_OK != res)
	{
		printf("\nFailure to JHCommGetTransportlayer!\n");
		ret = -1;
		goto ERROR_OPERATION;
	}

	res = JHCommGetNetArgStruct(&pargstruct, "192.168.1.3", 30000, 5000);
	if(JR_OK != res)
	{
		printf("\nFailure to JHCommGetNetArgStruct!\n");
		ret = -1;
		goto ERROR_OPERATION;
	}
#endif

	JHMountTransportLayer(hdl, (JHTRANSPORTLAYER *)(pjhtransportlayer), (const void *)(pargstruct));
	JHCommReleaseArgStruct(pargstruct);

	/* Draw line operation*/
	res = JHDrawLine(hdl, 0, 0, 0, 15);
	if (JR_OK == res)
	{
		printf("\nSuccessed in drawing line!\n");
		ret = 0;
	}
	else
	{
		printf("\n %d Failure to draw line!\n", res);
		ret = -1;
	}

ERROR_OPERATION:
	JHCommDeinit();

	/* Delete instance */
	JHDeleteInst(hdl);

	system("pause");

	return ret;
}

